var ws =
{
    webSocket: null,
    // 固定websocket地址
    ws_url: 'ws://localhost:9090',

    // 初始化websocket对象
    init: (address) => {
        // 判断浏览器是否支持WebSocket
        if (!("WebSocket" in window)) {
            console.log('浏览器不支持WebSocket')
            return null
        }
        //  根据URL获取websocket对象
        ws.webSocket = new WebSocket(ws_url + address);
        // 初始化websocket相关方法
        ws.webSocket.onopen = (event) => {
            console.log('建立连接：' + event);
        }

        ws.webSocket.onclse = (event) => {
            console.log('连接关闭：' + event);
        }

        ws.webSocket.onerror = () => {
            console.log('websocket通信发生错误!');
        }
    }

}

// 导出websocket对象
export default {
    ws
}

